﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDataBaseWork;
using XF.Meeting.Entity.dbEntity;
using XF.Meeting.Entity.DTO;
using XF.Meeting.Entity.Query;
using XF.Meeting.IDal;

namespace XF.Meeting.DAL
{
    public class SettingDal : BaseDAL, ISettingDal
    {
        /// <summary>
        /// 获取系统名称
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetSystemName(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetSystemName", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSystemName EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取AD设置
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetADsetting(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetADSetting", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetADSetting EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取系统预约显示时段（开始，结束）
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetSubscribe(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetSubscribe", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSubscribe EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取系统设置信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetSettingSystem(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetSettingSystem", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSettingSystem EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 修改系统设置信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateSettingSystem(SettingSystem entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@SystemName",entity.SystemName),
                  new SqlParameter("@CNumberLength",entity.CNumberLength),
                  new SqlParameter("@CNumberPrefix",entity.CNumberPrefix),
                  new SqlParameter("@SubscribeBegin",entity.SubscribeBegin),
                  new SqlParameter("@SubscribeEnd",entity.SubscribeEnd),
                  new SqlParameter("@CTimeLimit",entity.CTimeLimit),
                  new SqlParameter("@CReleaseTime",entity.CReleaseTime),
                  new SqlParameter("@MailType",entity.MailType),
                  new SqlParameter("@MailServer",entity.MailServer),
                  new SqlParameter("@MailPort",entity.MailPort),
                  new SqlParameter("@MailAdmin",entity.MailAdmin),
                  new SqlParameter("@MailPassword",entity.MailPassword),
                  new SqlParameter("@ScreenNotice",entity.ScreenNotice),
                  new SqlParameter("@BScreenINotice",entity.BScreenINotice),
                  new SqlParameter("@BScreenWTimeBegin",entity.BScreenWTimeBegin),
                  new SqlParameter("@BScreenWTimeEnd",entity.BScreenWTimeEnd),
                  new SqlParameter("@BScreenWelcome",entity.BScreenWelcome),
                  new SqlParameter("@EnclosureUrl",entity.EnclosureUrl),
                  new SqlParameter("@DataBaseIP",entity.DataBaseIP),
                  new SqlParameter("@DataBaseAccount",entity.DataBaseAccount),
                  new SqlParameter("@DataBasePassword",entity.DataBasePassword),
                  new SqlParameter("@FileName",entity.FileName),
                  new SqlParameter("@FileUrl",entity.FileUrl),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateSettingSystem", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateSettingSystem EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 获取第三方设置信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetSettingThirdParty(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetSettingThirdParty", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSettingThirdParty EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 修改第三方设置信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateSettingThirdParty(SettingThirdParty entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@ApiInterface",entity.ApiInterface),
                  new SqlParameter("@AppointProcessNo",entity.AppointProcessNo),
                  new SqlParameter("@SummaryProcessNo",entity.SummaryProcessNo),
                  new SqlParameter("@DDCorpId",entity.DDCorpId),
                  new SqlParameter("@DDAgentId",entity.DDAgentId),
                  new SqlParameter("@DDAppKey",entity.DDAppKey),
                  new SqlParameter("@DDAppSecret",entity.DDAppSecret),
                  new SqlParameter("@WechatCorpId",entity.WechatCorpId),
                  new SqlParameter("@WechatSecret",entity.WechatSecret),
                  new SqlParameter("@WechatAgentId",entity.WechatAgentId),
                  new SqlParameter("@ADIP",entity.ADIP),
                  new SqlParameter("@ADPort",entity.ADPort),
                  new SqlParameter("@ADDomainName",entity.ADDomainName),
                  new SqlParameter("@ADAccount",entity.ADAccount),
                  new SqlParameter("@ADPassword",entity.ADPassword),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateSettingThirdParty", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateSettingThirdParty EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 获取使用许可设置信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetSettingUseLicense(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetSettingUseLicense", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetSettingUseLicense EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 修改使用许可设置信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateSettingUseLicense(SettingUseLicense entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@TermOfValidity",entity.TermOfValidity),
                  new SqlParameter("@LicensesNumber",entity.LicensesNumber),
                  new SqlParameter("@MachineCode",entity.MachineCode),
                  new SqlParameter("@AuthorizationCode",entity.AuthorizationCode),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateSettingUseLicense", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateSettingUseLicense EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 新建区域
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> AddRegional(RegionalInfo entity, out string strError)
        {
            entity.Path = entity.Path;
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {

                  new SqlParameter("@RegionalName",entity.RegionalName),
                  new SqlParameter("@PID",entity.PID),
                  new SqlParameter("@Path",entity.Path),
                  new SqlParameter("@Sort",entity.Sort),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertSettingRegional", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertSettingRegional EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            if ( entity.ORIDs != null)
            {
                foreach (var item in entity.ORIDs)
                {
                    SqlParameter[] sqlParametersOr = new SqlParameter[] {

                  new SqlParameter("@RID",ReturnValue),
                  new SqlParameter("@ORID",item),


                };
                    CParameters parasOr = new CParameters();
                    parasOr.AddRange(sqlParametersOr);
                    if (!_db.ExcuteByTransaction(parasOr, "spInsertRegional_Organization_Map", out int ReturnValueOr, out strError))
                    {
                        bResult = false;
                        strError = string.Format("DBProvider spInsertRegional_Organization_Map EXECUTE_DB Error:{0}", strError);
                    }
                    else
                    {
                        strError = string.Empty;
                    }
                }
            }

            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 删除区域
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> DeleteRegional(RegionalInfo entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {


                  new SqlParameter("@ID",entity.ID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spDeleteRegional", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteRegional EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 编辑区域
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateRegional(RegionalInfo entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@RegionalName",entity.RegionalName),
                  new SqlParameter("@PID",entity.PID),
                  new SqlParameter("@Sort",entity.Sort),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateSettingRegional", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateSettingRegional EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            SqlParameter[] sqlParametersdelete = new SqlParameter[] {

                  new SqlParameter("@RID",entity.ID),

                };
            CParameters parasdelete = new CParameters();
            parasdelete.AddRange(sqlParametersdelete);
            if (!_db.ExcuteByTransaction(parasdelete, "spDeleteRegional_Organization_MapByRID", out int ReturnValuedelete, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteRegional_Organization_MapByRID EXECUTE_DB Error:{0}", strError);
                return Task.FromResult(bResult);
            }
            else
            {
                strError = string.Empty;
            }
            if ( entity.ORIDs != null)
            {
                foreach (var item in entity.ORIDs)
                {
                    SqlParameter[] sqlParametersupdate = new SqlParameter[] {

                  new SqlParameter("@RID",entity.ID),
                  new SqlParameter("@ORID",item),


                };
                    CParameters parasupdate = new CParameters();
                    parasupdate.AddRange(sqlParametersupdate);
                    if (!_db.ExcuteByTransaction(parasupdate, "spInsertRegional_Organization_Map", out int ReturnValueupdate, out strError))
                    {
                        bResult = false;
                        strError = string.Format("DBProvider spInsertRegional_Organization_Map EXECUTE_DB Error:{0}", strError);
                    }
                    else
                    {
                        strError = string.Empty;
                    }
                }
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 获取区域信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int, bool>> GetRegional(RegionalQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegional", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegional EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 获取区域(Pad)
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegionalForPad(out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalForPad", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalForPad EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }


            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取区域(Pad)
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegionalByPathForPad(RegionalInfo query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
               new SqlParameter("@Path",query.Path),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalByPathForPad", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalByPathForPad EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }


            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取区域下会议室ID和名称
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetCRoomNameByRid(RoomQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
               new SqlParameter("@RID",query.RID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomNameByRid", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomNameByRid EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }


            return Task.FromResult(ds.Tables[0]);
        }

        public Task<Tuple<DataTable, int, int, bool>> GetRegionalForMobile(RegionalQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                               new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalForMobile", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalForMobile EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);

        }
        public Task<DataTable> getMeetIdBystrBOID(string guid, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                               new SqlParameter("@guid",guid)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spgetMeetIdBystrBOID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spgetMeetIdBystrBOID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        /// <summary>
        /// 获取区域根节点信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegionalOne(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalOne", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalOne EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取区域根节点信息(管理员)
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegionalOneForAdmin(RegionalInfo query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                new SqlParameter("@ID",query.ID),
                new SqlParameter("@IsAdmin",query.IsAdmin),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalOneForAdmin", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalOneForAdmin EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据父ID获取区域信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegionalByPID(RegionalQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                 new SqlParameter("@PID",query.PID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegionalByPID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegionalByPID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取系统会议时长限制
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<MeetingTimeLimit> GetMeetingTimeLimit(out string strError)
        {
            List<MeetingTimeLimit> list = new List<MeetingTimeLimit>();
            SqlParameter[] sqlParameters = new SqlParameter[] {
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetMeetingTimeLimit", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetMeetingTimeLimit EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            list = TableToList.ToList<MeetingTimeLimit>(ds.Tables[0]);
            return Task.FromResult(list[0]);
        }

        /// <summary>
        /// 获取组织树
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetOrganizationTree(out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetOrganizationTree", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrganizationTree EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }



        /// <summary>
        /// 获取区域下的关联组织
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetRegional_Organization(Regional_Organization entity, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                new SqlParameter("@RID",entity.RID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRegional_Organization", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRegional_Organization EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }



        /// <summary>
        /// 获取行政组织根节点信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetOrganizationOne(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetOrganizationOne", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrganizationOne EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据父ID获取行政组织信息
        /// </summary>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetOrganizationByPID(OrganizationQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                 new SqlParameter("@PID",query.PID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetOrganizationByPID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrganizationByPID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
    }
}